﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Ext.Net;

public partial class SYS_POPEDOM_SysDefault_Manage : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void OnRefresh_Data(object sender, StoreRefreshDataEventArgs e)
    {
        try
        {
            Store1.DataSource = GetData();
            Store1.DataBind();
        }
        catch (Exception ex)
        {
            X.Msg.Alert("系统提示", "加载出错|" + ex.Message).Show();
        }
    }

    private DataTable GetData()
    {
        DataTable dtUser = CommonLib.BLL.SYS_USER.GetList("USER_ID='" + BS_LoginUserID + "'").Tables[0];
        if (dtUser == null || dtUser.Rows.Count < 1)
            throw new Exception("用户不存在");
        string subSys = dtUser.Rows[0]["SUB_SYSTEM"].ToString();
        DataTable dt = CommonLib.BLL.SYS_SUBSYSTEM.GetList("1=1 and SUB_SYSTEM !=5").Tables[0];
        dt.Columns.Add("IsDefault");
        foreach (DataRow row in dt.Rows)
        {
            if (row["SUB_SYSTEM"].ToString() == subSys)
                row["IsDefault"] = "是";
            else
                row["IsDefault"] = "否";
        }
        return dt;
    }

    [DirectMethod]
    public void OnAfterEdit(string id, string value)
    {
        var model = CommonLib.BLL.SYS_USER.GetModel(BS_LoginUserID);
        if (model == null)
            return;
        if (value == "是")
            model.SUB_SYSTEM = Convert.ToInt32(id);
        else
            model.SUB_SYSTEM = 0;
        CommonLib.BLL.SYS_USER.Update(model);
        Store1.CommitChanges();
        GridPanel1.Reload();
    }
}
